import {
    getModelDetail,
    saveModel,
    testEvent,
    getListData,
    getEventsList,
    setEventsList,
  } from "../server/eventApi";

  const initData = {
    detailData: {}, // 流程模型详细信息
  };

  export default {
    namespace: "flowEvent",
    state: {
      ...initData,
    },
    effects: {
        *getModelDetail({ payload }, { call, put }) {
          const { errCode, errMsg, datas = {} } = yield call(
            getModelDetail,
            payload, 
          );
          yield put({ type: "get/detailData", payload: datas || {} });
          return { errCode, errMsg, datas};
        },
        *saveModel({ payload }, { call, put }) {   // eslint-disable-line no-unused-vars
            const { errCode, errMsg, errortext } = yield call(saveModel, payload);
            return { errCode, errMsg: errMsg || errortext };
          },
          *testEvent({ payload }, { call }) {
            const { errCode, errMsg, errortext, datas } = yield call(testEvent, payload);
            return { errCode, errMsg: errMsg || errortext, datas };
          },
          *getListData({ payload }, { call }) {
            const { errCode, errMsg, errortext, datas,totalCount } = yield call(getListData, payload);
            return { errCode, errMsg: errMsg || errortext, datas,totalCount};
          },
          *getEventsList({ payload }, { call }) {
            const { errCode, errMsg, errortext, datas,totalCount } = yield call(getEventsList, payload);
            return { errCode, errMsg: errMsg || errortext, datas,totalCount};
          },
          *setEventsList({ payload },{ call }) {
            const { errCode, errMsg, errortext, datas,totalCount } = yield call(setEventsList, payload);
            return { errCode, errMsg: errMsg || errortext, datas,totalCount};
          },

    },
    reducers: {
        "get/detailData": (state, { payload }) => ({
          ...state,
          detailData: payload,
        }),
        clearData: () => ({ ...initData }),
    },
}